import React from 'react';
import {
  View,
  Text,
  TouchableOpacity,
} from 'react-native';

import Config from '../../config';
import SizeUtils from '../../common/SizeUtils';
import IMOne2OnePage from './IMOne2OnePage';
import IMConstants from './IMConstants';

//请求刷新的间隔
const REFRESH_INTERVAL = 3;


//用评论的协议来模拟聊天
export default class IMOne2OneCommentPage extends IMOne2OnePage {
  constructor(props) {
    super(props);

    this._refreshInterval = null;
  }

  componentDidMount() {
    super.componentDidMount();
    this._startRefreshInterval();
  }

  _dealEnterPage() {
    super._dealEnterPage();
    this._startRefreshInterval();
  }

  _dealLeavePage() {
    super._dealLeavePage();
    this._clearRefreshInterval();
  }

  _startRefreshInterval() {
    this._clearRefreshInterval();
    this._refreshInterval = setInterval(()=>{
      this._requestData();
    }, REFRESH_INTERVAL * 1000);
  }

  _clearRefreshInterval() {
    this._refreshInterval && clearInterval(this._refreshInterval);
  }

  _dealSendMessageSuccess() {
    super._dealSendMessageSuccess();
    this._requestData();
  }
}
